<template>
  <div class="comment-post">
    <van-field
      class="post-field"
      v-model.trim="message"
      rows="2"
      autosize
      type="textarea"
      maxlength="50"
      placeholder="请输入留言"
      show-word-limit
    />
    <van-button
      @click="sendComment"
      class="post-btn"
      :disabled="!message.length"
      >发布=={{articleId}}</van-button
    >
  </div>
</template>

<script>
import { addCommentApi } from "@/api";
export default {
  name: "",
  props: {
    target: {}
  },

  inject:['articleId'],

  data() {
    return {
      message: ""
    };
  },
  methods: {
    async sendComment() {
      const { data: res } = await addCommentApi({
        target: this.target,  //  如果对 文章进行评论 传递的是文章id  ,如果是对评论回复传的就是文章id
        content: this.message,
        art_id: this.target==this.articleId?null: this.articleId  //  
      });

       /* 
        target====文章或者评论id
        art_id===
            对文章评论  null
            对评论进行回复   文章id  评论id
        */

      this.message = "";
      console.log(res, 5555666);

      /* 
           成功后   关闭对话框  + 表单值清空  + 显示刚刚添加的评论
           */
      this.$emit("postshow", res.data.new_obj);
    }
  }
};
</script>

<style scoped lang="less">
.comment-post {
  display: flex;
  align-items: center;
  padding: 32px 0 32px 32px;
  .post-field {
    background-color: #f5f7f9;
  }
  .post-btn {
    width: 150px;
    border: none;
    padding: 0;
    color: #6ba3d8;
    &::before {
      display: none;
    }
  }
}
</style>
